﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using com.lover.astd.common.config;
using System.Windows.Forms;
using com.lover.astd.game.ui.server.impl;
using com.lover.astd.common.model;
using com.lover.astd.game.ui.server.impl.activities;
using com.lover.astd.game.ui.server.impl.economy;
using com.lover.astd.game.ui.server.impl.battle;
using com.lover.astd.game.ui.server.impl.secretary;
using System.Drawing;
using com.lover.astd.game.ui.server.impl.troop;
using com.lover.astd.game.ui.server.impl.equipment;
using System.Text.RegularExpressions;
using mshtml;
using System.Net;
using System.Security.Cryptography;
using com.lover.astd.common.manager;
using com.lover.astd.common;
using com.lover.astd.common.model.enumer;
using com.lover.common;
using AxSHDocVw;

namespace com.lover.astd.game.ui.server
{
    public class PartnerBase : IServer
    {
        protected LogLevel _loglevel = LogLevel.Info;
        #region inner fields
        protected enum LogLevel 
        {
            Debug, Info, Error
        }
        /// <summary>
        /// 0=未挂机, 1=挂机中
        /// </summary>
        private int _serverStatus = 0;
        private bool _exitThread = false;
        private bool _threadAborted = false;
        private System.Threading.Thread _backThread;
        
        protected LogHelper _logger;
        private List<Cookie> _cookies = new List<Cookie>();

        private List<LogicServer> _servers;
        private List<ServerRunConfig> _todo_servers;
        //private CommonServer _commonServer;
        private bool _runTemp = false;
        private LogicServer _tempServer;
        private long _next_temp_time = 0;

        protected MainForm _mainForm;
        protected RichTextBox _logbox;
        protected Label _logLabel;
        protected string _gameUrl;
        /// <summary>
        /// 游戏地址
        /// </summary>
        public string GameUrl
        {
            get { return _gameUrl; }
            set { 
                _gameUrl = value;
                Uri uri = new Uri(_gameUrl);
                _gameUrl = String.Format("{0}://{1}", uri.Scheme, uri.Host);
                _gameRootUrl = String.Format("{0}://{1}/root/", uri.Scheme, uri.Host);
            }
        }
        private string _gameRootUrl;
        public string GameRootUrl { get { return _gameRootUrl; } }
        #endregion

        public PartnerBase()
        {
            if (GlobalConfig.getInstance().IsDebug) _loglevel = LogLevel.Debug;

            _servers = new List<LogicServer>();
            _todo_servers = new List<ServerRunConfig>();
        }

        #region timers

        private void backThreadProc()
        {
            int do_counter = -1, idle_counter = 0;
            try
            {
                while (!_exitThread)
                {
                    string server_status = "";
                    if (_runTemp && _tempServer != null && _next_temp_time < TimeMgr.TimeStamp)
                    {
                        //if (_tempServer is ITempServer)
                        //{
                        //    if (!(_tempServer as ITempServer).isFinished())
                        //    {
                        //        //_next_temp_time = _tempServer.execute();
                        //        _next_temp_time = _next_temp_time + TimeMgr.TimeStamp;
                        //        string status = (_tempServer as ITempServer).getStatus();
                        //        if (_mainForm.InvokeRequired) _mainForm.txt_servers.Invoke(new ParamDelegate(setTempStatus), status);
                        //        else setTempStatus(status);
                        //        if ((_tempServer as ITempServer).isFinished()) stopTempServer();
                        //        DateTime dt = new DateTime(_next_temp_time * 10000);
                        //        server_status = String.Format("{0} : {1}\r\n", dt.ToString("HH:mm:ss"), "临时任务");
                        //    }
                        //    else stopTempServer();
                        //}
                    }
                    if (_todo_servers.Count == 0)
                    {
                        do_counter = 0;
                        System.Threading.Thread.Sleep(100);
                        idle_counter++;
                        if (idle_counter >= 20)
                        {
                            if (_mainForm.txt_servers.InvokeRequired) _mainForm.txt_servers.Invoke(new ParamDelegate(setServerText), server_status);
                            else setServerText(server_status);
                        }
                        continue;
                    }
                    // 最开始执行一次, 然后没过2秒执行一次
                    if (do_counter < 20 && do_counter >= 0)
                    {
                        System.Threading.Thread.Sleep(100);
                        do_counter++;
                        continue;
                    }
                    do_counter = 0;
                    ServerRunConfig conf = null;

                    lock (_todo_servers)
                    {
                        for (int i = 0; i < _todo_servers.Count; i++)
                        {
                            if (_todo_servers[i].timestamp < TimeMgr.TimeStamp)
                            {
                                conf = _todo_servers[i];
                                _todo_servers.RemoveAt(i); i--;
                                long next = 0; // conf.server.execute();

                                addRunConfig(next, conf.server);
                            }
                        }
                        int len = _todo_servers.Count;
                        for (int i = 0; i < len - 1; i++)
                        {
                            for (int j = i + 1; j < len; j++)
                            {
                                if (_todo_servers[i].timestamp > _todo_servers[j].timestamp)
                                {
                                    ServerRunConfig tmpconf = _todo_servers[i];
                                    _todo_servers[i] = _todo_servers[j];
                                    _todo_servers[j] = tmpconf;
                                }
                            }
                        }
                        for (int i = 0; i < len; i++)
                        {
                            DateTime dt = new DateTime(_todo_servers[i].timestamp * 10000);
                            string sname = _todo_servers[i].server.ServerReadableName;
                            string text = String.Format("{0} : {1}\r\n", dt.ToString("HH:mm:ss"), sname);
                            server_status += text;
                        }
                    }

                    if (_mainForm.txt_servers.InvokeRequired) _mainForm.txt_servers.Invoke(new ParamDelegate(setServerText), server_status);
                    else setServerText(server_status);

                    LogSingleSafe("挂机中...");
                }
            }
            catch (System.Threading.ThreadInterruptedException ex) { Console.WriteLine(ex.ToString()); }
            catch (Exception ex)
            {
                LogFile(String.Format("出现错误:MSG=[{0}], Stack=[{1}], SOURCE=[{2}]", ex.Message, ex.StackTrace, ex.Source));
                startServer();
            }
        }
        private delegate void ParamDelegate(string status);
        private void setServerText(string status) { _mainForm.txt_servers.Text = status; }
        public void saveSettings()
        {
            // save server settings
            for (int i = 0, len = _servers.Count; i < len; i++)
            {
                _servers[i].saveSettings();
            }
        }
        public void loadDefaultSettings()
        {
            // save server settings
            for (int i = 0, len = _servers.Count; i < len; i++)
            {
                _servers[i].loadDefaultSettings();
            }
        }
        /// <summary>
        /// 通知某个服务立刻执行
        /// </summary>
        /// <param name="servername"></param>
        public void notifyServer(string servername)
        {
            for (int i=0, len=_todo_servers.Count; i<len; i++)
            {
                ServerRunConfig conf = _todo_servers[i];
                if (conf.server.ServerName.Equals(servername))
                {
                    conf.timestamp = TimeMgr.TimeStamp + 1000;
                }
            }
        }
        #endregion

        #region inner operations
        public string Md5Hash(string rawString)
        {
            MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
            byte[] rawBytes = UTF8Encoding.UTF8.GetBytes(rawString);
            byte[] enBytes = provider.ComputeHash(rawBytes);
            string enString = BitConverter.ToString(enBytes);
            return enString;
        }
        public ServerResult getXml(string url, string desc)
        {
            LogSingleSafe(desc);
            ServerResult result = doGet(url);
            if (result == null) return null;
            LogDebug(result.getDebugInfo());
            if (!result.HttpSucceed)
            {
                handleGlobalError(result);
                return null;
            }
            if (!result.CmdSucceed)
            {
                LogError(String.Format("{0}错误, [{1}]", desc, result.CmdError));
                if (result.CmdError.IndexOf("连接已超时") >= 0 || result.CmdError.IndexOf("用户已在别处登陆") >= 0 || result.CmdError.IndexOf("验证码") >= 0)
                {
                    _mainForm.startReLoginTimer();
                    stopServer();
                    return null;
                }
            }
            XmlNode playerinfo = result.CmdResult.SelectSingleNode("/results/playerupdateinfo");
            if (playerinfo != null)
            {
                _mainForm.GameUser.refreshPlayerInfo(playerinfo);
                if (_mainForm != null) refreshPlayerSafe();
            }
            XmlNode battleinfo = result.CmdResult.SelectSingleNode("/results/playerbattleinfo");
            if (battleinfo != null)
            {
                _mainForm.GameUser.refreshPlayerInfo(battleinfo);
                if (_mainForm != null) refreshPlayerSafe();
            }
            return result;
        }
        private delegate void RefreshPlayerDelegate();
        private RefreshPlayerDelegate _rfPlayer;
        public void refreshPlayerSafe()
        {
            if (_rfPlayer == null) _rfPlayer = new RefreshPlayerDelegate(refreshPlayer);
            if (_mainForm.InvokeRequired) _mainForm.Invoke(_rfPlayer);
            else refreshPlayer();
        }
        public virtual void refreshPlayer()
        {
            _mainForm.refreshPlayerInfo();
        }
        public ServerResult postXml(string url, string data, string desc)
        {
            LogSingleSafe(desc);
            ServerResult result = doPost(url, data);
            if (result == null) return null;
            LogDebug(result.getDebugInfo());
            if (!result.HttpSucceed)
            {
                handleGlobalError(result);
                return null;
            }
            if (!result.CmdSucceed)
            {
                LogError(String.Format("{0}错误, [{1}]", desc, result.CmdError));
                if (result.CmdError.IndexOf("连接已超时") >= 0 || result.CmdError.IndexOf("用户已在别处登陆") >= 0 || result.CmdError.IndexOf("验证码") >= 0)
                {
                    _mainForm.startReLoginTimer();
                    stopServer();
                    return null;
                }
            }
            XmlNode playerinfo = result.CmdResult.SelectSingleNode("/results/playerupdateinfo");
            if (playerinfo != null)
            {
                _mainForm.GameUser.refreshPlayerInfo(playerinfo);
                if (_mainForm != null) refreshPlayerSafe();
            }
            XmlNode battleinfo = result.CmdResult.SelectSingleNode("/results/playerbattleinfo");
            if (battleinfo != null)
            {
                _mainForm.GameUser.refreshPlayerInfo(battleinfo);
                if (_mainForm != null) refreshPlayerSafe();
            }
            return result;
        }
        protected bool ifSuccess(XmlDocument doc)
        {
            XmlNode node = doc.SelectSingleNode("/results/state");
            return node.InnerText == "1";
        }
        internal MainForm getMainForm() { return _mainForm; }

        private delegate void LogSingleDelegate(string logtext);
        private LogSingleDelegate _logSingleDelegate;
        public void LogSingleSafe(string logtext)
        {
            if (_logSingleDelegate == null) _logSingleDelegate = new LogSingleDelegate(LogSingle);
            if (_logLabel.InvokeRequired) _logLabel.Invoke(_logSingleDelegate, logtext);
            else LogSingle(logtext);
        }
        internal void LogSingle(string logtext) 
        {
            _logLabel.Text = logtext;
        }
        public void LogDebug(string logtext) { LogSafe(logtext, LogLevel.Debug, Color.Gray); }
        public void LogInfo(string logtext, Color logColor) { LogSafe(logtext, LogLevel.Info, logColor); }
        public void LogError(string logtext) { LogSafe(logtext, LogLevel.Error, Color.Red); }

        private delegate void LogDelegate(string logtext, LogLevel level, Color logColor);
        private LogDelegate _logDelegate;
        protected void LogSafe(string logtext, LogLevel level, Color logColor)
        {
            if (_logDelegate == null) _logDelegate = new LogDelegate(Log);
            if (_logbox.InvokeRequired) _logbox.Invoke(_logDelegate, logtext, level, logColor);
            else Log(logtext, level, logColor);
        }
        protected void Log(string logtext, LogLevel level, Color logColor)
        {
            if (level < _loglevel) return;
            string logt = String.Format("[{0:MM-dd HH:mm:ss}]: {1}", TimeMgr.DateTimeNow, logtext);
            if(_logger != null) _logger.log(logt);
            if (level > LogLevel.Debug)
            {
                _logbox.AppendText(logt);
                _logbox.Select(_logbox.Text.Length - logt.Length, logt.Length);
                _logbox.SelectionColor = logColor;
                _logbox.Select(_logbox.Text.Length, 0);
                _logbox.AppendText("\n");
                _logbox.ScrollToCaret();
            }
        }
        protected void LogFile(string logtext)
        {
            string logt = String.Format("[{0:MM-dd HH:mm:ss}]: {1}", TimeMgr.DateTimeNow, logtext);
            if (_logger != null) _logger.log(logt);
        }
        private delegate void LogSurpriseDelegate(string logtext, Color logColor);
        private LogSurpriseDelegate _logSurpriseDelegate;
        protected void LogSurpriseSafe(string logtext, Color logColor)
        {
            if (_logSurpriseDelegate == null) _logSurpriseDelegate = new LogSurpriseDelegate(LogSurprise);
            if (_mainForm.logSurpise.InvokeRequired) _mainForm.logSurpise.Invoke(_logSurpriseDelegate, logtext, logColor);
            else LogSurprise(logtext, logColor);
        }
        public void LogSurprise(string logtext, Color logColor)
        {
            string logt = String.Format("[{0:MM-dd HH:mm:ss}]: {1}", DateTime.Now, logtext);
            _mainForm.logSurpise.AppendText(logt);
            _mainForm.logSurpise.Select(_logbox.Text.Length - logt.Length, logt.Length);
            _mainForm.logSurpise.SelectionColor = logColor;
            _mainForm.logSurpise.Select(_logbox.Text.Length, 0);
            _mainForm.logSurpise.AppendText("\n");
            _mainForm.logSurpise.ScrollToCaret();
        }
        private void handleGlobalError(ServerResult result)
        {
            // 如果是http错误, 那么停止, 10分钟后重新登录, ||||| 貌似有问题的, 网络情况不好时这种情况很常见的, 所以忽略吧
            //stopServer();
            //_httperror_timer.Start();
        }
        protected ServerResult doGet(string url) 
        {
            string surl = String.Format("{0}{1}?{2}", _gameUrl, url, TimeMgr.TimeStamp);
            LogDebug(String.Format("get url={0}", surl));
            ServerResult result = null;
            try
            {
                List<Cookie> cookies = new List<Cookie>();
                string retstr = TransferMgr.doGet(surl, ref _cookies);
                result = new ServerResult(retstr);
            }
            catch (System.Exception ex)
            {
                LogError(ex.Message);
            }
            return result;
        }
        protected ServerResult doPost(string url, string data) 
        {
            string surl = String.Format("{0}{1}?{2}", _gameUrl, url, TimeMgr.TimeStamp);
            LogDebug(String.Format("post url={0}, data={1}", surl, data));
            ServerResult result = null;
            try
            {
                string retstr = TransferMgr.doPost(surl, data, ref _cookies);
                result = new ServerResult(retstr);
            }
            catch (System.Exception ex)
            {
                LogError(ex.Message);
            }
            return result;
        }
        public void refreshPlayerInfo()
        {
            //if (_commonServer != null) _commonServer.initVariableSafe();
        }
        /// <summary> 
        /// 
        /// </summary>
        /// <param name="timest">单位:毫秒</param>
        /// <param name="ser"></param>
        public void addRunConfig(long timest, LogicServer ser)
        {
            // 首先查找_todo_servers里面是否已经有了这个server, 如果有了, 那么替换, 否则插入
            long tmpstmp = timest + TimeMgr.TimeStamp;
            bool found = false;
            for (int i = 0; i < _todo_servers.Count; i++)
            {
                ServerRunConfig tconf = _todo_servers[i];
                if (tconf.server.ServerName.Equals(ser.ServerName))
                {
                    tconf.timestamp = tmpstmp;
                    found = true;
                }
            }
            if (found) return;

            ServerRunConfig conf = new ServerRunConfig();
            conf.timestamp = tmpstmp;
            conf.server = ser;

            _todo_servers.Add(conf);
        }
        private class ServerRunConfig : IComparable<ServerRunConfig>
        {
            public long timestamp;
            public LogicServer server;

            #region IComparable<ServerRunConfig> 成员

            public int CompareTo(ServerRunConfig other)
            {
                return (int)(other.timestamp - this.timestamp);
            }

            #endregion
        }
        #endregion

        #region init servers
        public void reLogin()
        {
            stopServer();
            //TODO: do re_login
            _mainForm.startRelogin();
        }

        #region init server functions
        void LogicServer_ReadyEventHandler()
        {
            // check if all server is ready, if so, enable host button
            for (int i = 0, len = _servers.Count; i < len; i++)
            {
                //if (!_servers[i].isReady) return;
            }
            // 如果正在挂机, 那么这里是读取数据
            if (_serverStatus == 1) startServer();
            else _mainForm.initializeComplete();

            LogSingleSafe("挂机就绪");
        }
        public void startServer()
        {
            stopServer();
            if (_threadAborted)
            {
                _backThread = new System.Threading.Thread(backThreadProc);
                _backThread.Start();
                _threadAborted = false;
            }
            for (int i = 0, len = _servers.Count; i < len; i++)
            {
                addRunConfig(0, _servers[i]);
            }
            _serverStatus = 1;
            setFormStatusSafe(common.model.enumer.AccountStatus.Running);
        }
        public void stopServer(bool is_user_operate=false)
        {
            _todo_servers.Clear();
            LogSingleSafe("挂机停止");
            if (_mainForm.txt_servers.InvokeRequired) _mainForm.txt_servers.Invoke(new ParamDelegate(setServerText), "");
            else setServerText("");
            if (is_user_operate) _serverStatus = 0;
            setFormStatusSafe(common.model.enumer.AccountStatus.Stopped);
            try
            {
                _threadAborted = true;
                if (_backThread != null)
                {
                    _backThread.Join(0);
                    _backThread.Interrupt();
                }
            }
            catch{ }
        }
        public void addTempServer(LogicServer ser)
        {
            _runTemp = true;
            //ser.setVariables(_mainForm, this);
            _tempServer = ser;
            _next_temp_time = 0;
        }
        public void stopTempServer()
        {
            _runTemp = false;
            _tempServer = null;
            _next_temp_time = 0;
            if (_mainForm.InvokeRequired) _mainForm.Invoke(new StopTempServerDelegate(stopTempServerUi));
            else stopTempServerUi();
        }
        private void setTempStatus(string status) { }//_mainForm.updateTempStatus(status); }
        private delegate void StopTempServerDelegate();
        private void stopTempServerUi() { }//_mainForm.tempServerStopped(); }
        public void LogTemp(string logtext) { logTempSafe(logtext); }
        private delegate void logTempDelegate(string text);
        private logTempDelegate _logTempSafe;
        private void logTempSafe(string text)
        {
            if (_logTempSafe == null) _logTempSafe = new logTempDelegate(logTemp);
            if (_mainForm.InvokeRequired) _mainForm.Invoke(_logTempSafe, text);
            else logTemp(text);
        }
        private void logTemp(string text)
        {
            string logt = String.Format("[{0:MM-dd HH:mm:ss}]: {1}", TimeMgr.DateTimeNow, text);
            if (_logger != null) _logger.log(logt);
            _mainForm.logTemp.AppendText(logt);
            _mainForm.logTemp.AppendText("\n");
            _mainForm.logTemp.ScrollToCaret();
        }
        private delegate void setFormStatusSafeDelegate(AccountStatus status);
        private setFormStatusSafeDelegate _setFormStatusSafe;
        public void setFormStatusSafe(AccountStatus status)
        {
            if (_setFormStatusSafe == null) _setFormStatusSafe = new setFormStatusSafeDelegate(setFormStatus);
            if (_mainForm.InvokeRequired) _mainForm.Invoke(_setFormStatusSafe, status);
            else setFormStatus(status);
        }
        private void setFormStatus(AccountStatus status)
        {
        }
        public virtual void releaseResources()
        {
            stopServer();
            _exitThread = true;
            for (int i = 0, len = _servers.Count; i < len; i++)
            {
                _servers[i].release();
            }
        }
        public void initializeEnvironment()
        {
            // read configs
            //if (!_commonServer.doInitialize()) return;
            User u = _mainForm.GameUser;
            AccountData acc = _mainForm.Account;
            if(_logger == null) _logger = new LogHelper(EnumString.getString(acc.Server_type), acc.ServerId, u.Username);
            _mainForm.Account.GameConf = new GameConfig(EnumString.getString(acc.Server_type), acc.ServerId, u.Username);
            _mainForm.Account.GameConf.loadSettings();
            buildAllServers();
        }
        #endregion

        private void buildAllServers()
        {
            int level = _mainForm.GameUser.Level;
            // stop all servers and remove them
            lock (_servers)
            {
                //for (int i = 0, len = _servers.Count; i < len; i++) _servers[i].stop();
                if (_servers.Count == 0)
                {
                    //_servers.Add(_commonServer);

                    if (!GlobalConfig.getInstance().IsDebug)
                    {
                        //_servers.Add(new BuildingServer());
                        //_servers.Add(new DinnerServer());
                        //_servers.Add(new FeteServer());
                        //_servers.Add(new ImposeServer());
                        //_servers.Add(new MarketServer());
                        //_servers.Add(new StockServer());
                        //_servers.Add(new StoneServer());
                        //_servers.Add(new MovableServer());
                        //_servers.Add(new HeroTrainServer());
                        //_servers.Add(new HeroWashServer());
                        //_servers.Add(new AttackServer());
                        //_servers.Add(new BattleServer());
                        //_servers.Add(new SecretaryServer());

                        //_servers.Add(new QhServer());
                        //_servers.Add(new MhServer());
                        //_servers.Add(new WeaponServer());
                        //_servers.Add(new StoreServer());
                        //_servers.Add(new MerchantServer());
                        //_servers.Add(new PolishServer());
                        //_servers.Add(new DailyWeaponServer());

                        //_servers.Add(new CrossPlatformCompeteServer());
                        //_servers.Add(new GiftEventServer());
                        //_servers.Add(new ArchServer());
                        //_servers.Add(new TreasureGameServer());
                        //_servers.Add(new KfBanquetServer());
                        //_servers.Add(new ResCampaignServer());
                        //_servers.Add(new DailyTreasureGameServer());
                        //_servers.Add(new SilverFlopServer());
                        //_servers.Add(new GemFlopServer());
                        //_servers.Add(new WorldArmyServer());
                        //_servers.Add(new PlayerCompeteServer());
                        //_servers.Add(new JailEventServer());
                        //_servers.Add(new FestivalEventServer());
                    }
                    else
                    {
                        initDebugServer();
                    }


                    // initialize all servers
                    for (int i = 0, len = _servers.Count; i < len; i++)
                    {
                        //_servers[i].setVariables(_mainForm, this);
                        //_servers[i].ReadyEventHandler += LogicServer_ReadyEventHandler;
                    }
                }

                for (int i = 0; i < _servers.Count; i++)
                {
                    //_servers[i].initVariableSafe();
                }
            }
        }

        #endregion
        private string _jsessionid = "";
        public void setSession(MainForm frm, string jsessionId, string gameUrl, bool direct_start_game=false)
        {
            GameUrl = gameUrl;
            _cookies.Clear();
            Uri game_uri = new Uri(gameUrl);
            Cookie cook = new Cookie();
            cook.Path = "/root";
            cook.Domain = game_uri.Host;
            cook.Name = "JSESSIONID";
            cook.Value = jsessionId;
            _cookies.Add(cook);
            _jsessionid = jsessionId;

            _mainForm = frm;
            _logbox = _mainForm.logText;
            _logLabel = _mainForm.lblStatus;
            //if (_commonServer == null) _commonServer = new CommonServer();
            //_commonServer.setVariables(_mainForm, this);

            if (direct_start_game) _serverStatus = 1;
            else _serverStatus = 0;

            initializeEnvironment();
        }

        private void initDebugServer()
        {
            //_servers.Add(new BuildingServer());
            //_servers.Add(new DinnerServer());
            //_servers.Add(new FeteServer());
            //_servers.Add(new ImposeServer());
            //_servers.Add(new MarketServer());
            //_servers.Add(new NationTaskServer());
            //_servers.Add(new OfficerServer());
            //_servers.Add(new StockServer());
            //_servers.Add(new StoneServer());
            //_servers.Add(new HeroTrainServer());
            //_servers.Add(new HeroWashServer());
            //_servers.Add(new DailyEventServer());
            //_servers.Add(new AttackServer());
            //_servers.Add(new BattleServer());
            //_servers.Add(new DailyTaskServer());
            //_servers.Add(new SecretaryServer());

            //_servers.Add(new QhServer());
            //_servers.Add(new MhServer());
            //_servers.Add(new WeaponServer());
            //_servers.Add(new StoreServer());
            //_servers.Add(new MerchantServer());
            //_servers.Add(new PolishServer());
            //_servers.Add(new DailyWeaponServer());

            //_servers.Add(new CrossPlatformCompeteServer());
            //_servers.Add(new GiftEventServer());
            //_servers.Add(new ArchServer());
            //_servers.Add(new TreasureGameServer());
            //_servers.Add(new KfBanquetServer());
            //_servers.Add(new ResCampaignServer());
            //_servers.Add(new DailyTreasureGameServer());
            //_servers.Add(new SilverFlopServer());
            //_servers.Add(new GemFlopServer());
            //_servers.Add(new WorldArmyServer());
            //_servers.Add(new PlayerCompeteServer());
            //_servers.Add(new MovableServer());

            //_servers.Add(new FestivalEventServer());
        }
        public void doTest()
        {
            //_commonServer.doInitialize();
            //_commonServer.getExtraInfo();
            //_commonServer.getExtraInfo2();
            //AttackServer ser = new AttackServer();
            //ser.setVariables(_mainForm, this);

            //ser.getWeaveInfo();
            //ser.doWeave();
            ////ser.getNewAreaInfo();
            //ser.getFlopInfo();
            //ser.getCampaignList();
            //ser.startCampaign(29, "测试");
            //ser.startCampaign(29, "测试");
            //ser.completeCampaign();
            //ser.getCampaignInfo();
            //ser.getCampaignReward(0);
        }

        public void init_completed()
        {
            throw new NotImplementedException();
        }

        public void startReLoginTimer()
        {
            _mainForm.startReLoginTimer();
        }
        public string getJSessionId() { return _jsessionid; }
    }
}
